package com.kangfu.api.controller;

import com.kangfu.api.interceptor.AuthorizationInterceptor;
import com.kangfu.api.service.ILeaveRecordService;
import com.kangfu.common.model.AjaxResult;
import com.kangfu.db.domain.entity.LeaveRecord;
import com.kangfu.db.model.request.LeaveRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/leave")
public class LeaveRecordController {

    @Autowired
    public ILeaveRecordService leaveRecordService;

    @PostMapping("/add")
    public AjaxResult add(@RequestAttribute(AuthorizationInterceptor.LOGIN_USER_ID) int userId, @RequestBody LeaveRequest leaveRequest) {
        leaveRecordService.insertLeaveRecord(userId, leaveRequest);
        return AjaxResult.success();
    }


    @GetMapping("/list")
    public AjaxResult list(@RequestAttribute(AuthorizationInterceptor.LOGIN_USER_ID) int userId, @RequestParam(name = "page", defaultValue = "1") int page) {
        List<LeaveRecord> list = leaveRecordService.selectLeaveRecordList(userId, page);
        return AjaxResult.success(list);
    }

}
